package cn.jiadakeji.parent.controller;

import cn.jiadakeji.parent.common.core.controller.BaseController;
import cn.jiadakeji.parent.common.core.domain.AjaxResult;
import cn.jiadakeji.parent.common.page.TableDataInfo;
import cn.jiadakeji.parent.common.util.SecurityUtils;
import cn.jiadakeji.parent.domain.Student;
import cn.jiadakeji.parent.dto.CustomerJwtDTO;
import cn.jiadakeji.parent.dto.StudentDTO;
import cn.jiadakeji.parent.service.StudentParentRelationService;
import cn.jiadakeji.parent.vo.StudentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author heyanfeng
 * @create 2022-03-10 10:37
 */
@Api(value = "学生家长关联信息", tags = {"学生家长关联信息接口"})
@RestController
@RequestMapping("/studentParentRelation")
public class StudentParentRelationController extends BaseController {

    @Autowired
    private StudentParentRelationService relationService;

    CustomerJwtDTO loginUser = SecurityUtils.getLoginUser();

    @ApiOperation("查找家长关联的学生信息")
    @GetMapping("/relation")
    public TableDataInfo getStudentRelation(){
        startPage();
        List<StudentDTO> studentList = relationService.getStudentRelation(loginUser.getStudentParentId());
        return getDataTable(studentList);
    }

    @ApiOperation("确认关联学生")
    @GetMapping("/confirm/{studentId}")
    public AjaxResult confirmRelation(
            @ApiParam("学生ID")
            @PathVariable("studentId") String studentId
    ) {

        Boolean aBoolean = relationService.confirmRelation(loginUser.getStudentParentId(), studentId);
        return aBoolean ? AjaxResult.success("关联学生成功") : AjaxResult.error("关联学生失败");

    }

    @ApiOperation("解除关联学生")
    @GetMapping("/remove/{studentId}")
    public AjaxResult removeRelation(
            @ApiParam("学生ID")
            @PathVariable("studentId") String studentId
    ) {
        Boolean aBoolean = relationService.removeRelation(loginUser.getStudentParentId(), studentId);
        return aBoolean ? AjaxResult.success("解除关联成功") : AjaxResult.error("解除关联失败");
    }


}
